#if 1
#include <iostream>
#include <boost/asio.hpp>
#include "http_server/http_server.hpp"

int main(int argc, char *argv[])
{
    try
    {
        if (argc != 2)
        {
            std::cerr << "Usage: http_server <port>\n";
            return 1;
        }

        boost::asio::io_context io_context;

        HttpServer server(io_context, std::atoi(argv[1]) /*port*/);

        io_context.run(); // 开始事件循环
    }
    catch (std::exception &e)
    {
        std::cerr << "Exception: " << e.what() << "\n";
    }

    return 0;
}

#elif 1
#include <iostream>
#include <memory>

class MyClass : public std::enable_shared_from_this<MyClass>
{
public:
    void print()
    {
        std::cout << "Hello from MyClass" << std::endl;
    }

    void start()
    {
        auto self = shared_from_this();
        std::cout << "Reference count in start(): " << self.use_count() << std::endl;
        // 在这里可以安全地使用 self
        print();
    }
};

int main()
{
    auto ptr = std::make_shared<MyClass>();
    std::cout << "Reference count after creation: " << ptr.use_count() << std::endl;

    ptr->start();

    std::cout << "Reference count after start(): " << ptr.use_count() << std::endl;
    return 0;
}

#endif
